using System;
using System.ComponentModel;
using System.Windows.Input;

namespace wpffc.contracts.viewmodels.commands
{
    public interface IFlowCommand<out T> : ICommand
    {
        void In_IsEnabled(bool state);

        event Action<T> Out_Execute;
    }


    public class FlowCommand<T> : IFlowCommand<T>, INotifyPropertyChanged
    {
        private readonly Func<object, T> _map;

        public FlowCommand() { _map = p => (T)p; }
        public FlowCommand(Func<object, T> map) { _map = map; }


        public virtual void Execute(object parameter)
        {
            this.Out_Execute(_map(parameter));
        }


        public bool CanExecute(object parameter) { return _isEnabled; }
        public event EventHandler CanExecuteChanged = delegate { };

        public event Action<T> Out_Execute;
        protected void Raise_Out_Execute(T message) { this.Out_Execute(message); }


        private bool _isEnabled = true;
        public bool IsEnabled
        {
            get { return _isEnabled; }
        }
        public void In_IsEnabled(bool state)
        {
            _isEnabled = state;
            this.CanExecuteChanged(this, EventArgs.Empty);
            this.PropertyChanged(this, new PropertyChangedEventArgs("IsEnabled"));
        }


        public event PropertyChangedEventHandler PropertyChanged = delegate { };
    }
}